1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use super::*;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Bool;
impl Bool {
pub const BOOL_CODE: u64 = 0x424f4f4c;
pub const TRUE_CODE: u64 = 0x54525545;
pub const FALSE_CODE: u64 = 0x46414c5345;
}
impl Value for Bool {
#[inline]
fn is_ty(&self) -> bool {
true
}
#[inline]
fn elem_linearity(&self) -> Result<Linearity, Error> {
Ok(Linearity::NONLINEAR)
}
#[inline]
fn ty(&self) -> &ValId {
&*SET
}
#[inline]
fn is_const(&self) -> bool {
true
}
fn subtype(&self, other: &ValId, _variance: Variance) -> Result<Match, Error> {
match other.as_enum() {
ValueEnum::Bool(_) => Ok(Match::dependency(Usage::OBSERVED)),
_ => Err(Error::TypeMismatch),
}
}
#[inline]
fn into_enum(self) -> ValueEnum {
ValueEnum::Bool(self)
}
#[inline]
fn into_valid(self) -> ValId {
BOOL.clone()
}
#[inline]
fn code(&self) -> u64 {
Self::BOOL_CODE
}
#[inline]
fn normal_code(&self) -> u64 {
Self::BOOL_CODE
}
}
impl Value for bool {
#[inline]
fn into_enum(self) -> ValueEnum {
ValueEnum::Boolean(self)
}
#[inline]
fn ty(&self) -> &ValId {
&*BOOL
}
#[inline]
fn elem_linearity(&self) -> Result<Linearity, Error> {
Ok(Linearity::NONLINEAR)
}
#[inline]
fn is_const(&self) -> bool {
true
}
#[inline]
fn into_valid(self) -> ValId {
if self {
TRUE.clone()
} else {
FALSE.clone()
}
}
#[inline]
fn code(&self) -> u64 {
if *self {
Bool::TRUE_CODE
} else {
Bool::FALSE_CODE
}
}
}
lazy_static! {
pub static ref BOOL: ValId = ValId::new_direct(ValueEnum::Bool(Bool));
pub static ref TRUE: ValId = ValId::new_direct(ValueEnum::Boolean(true));
pub static ref FALSE: ValId = ValId::new_direct(ValueEnum::Boolean(false));
}